<template>
  <div id="app">
    <div class="container">
      <h1>我的任务管理器</h1>
      
      <!-- 添加任务表单 -->
      <div class="add-task">
        <input 
          v-model="newTask" 
          @keyup.enter="addTask"
          placeholder="输入新任务..."
          class="task-input"
        >
        <button @click="addTask" class="add-btn">添加</button>
      </div>
      
      <!-- 任务列表 -->
      <div class="task-list">
        <div 
          v-for="(task, index) in tasks" 
          :key="index" 
          :class="['task-item', { completed: task.completed }]"
        >
          <input 
            type="checkbox" 
            v-model="task.completed"
            class="task-checkbox"
          >
          <span class="task-text">{{ task.text }}</span>
          <button @click="removeTask(index)" class="delete-btn">删除</button>
        </div>
      </div>
      
      <!-- 任务统计 -->
      <div class="task-stats">
        <p>总任务: {{ totalTasks }} | 已完成: {{ completedTasks }} | 未完成: {{ pendingTasks }}</p>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'App',
  data() {
    return {
      newTask: '',
      tasks: [
        { text: '学习 Vue 基础', completed: true },
        { text: '创建第一个 Vue 项目', completed: false },
        { text: '理解组件概念', completed: false }
      ]
    }
  },
  computed: {
    totalTasks() {
      return this.tasks.length
    },
    completedTasks() {
      return this.tasks.filter(task => task.completed).length
    },
    pendingTasks() {
      return this.totalTasks - this.completedTasks
    }
  },
  methods: {
    addTask() {
      if (this.newTask.trim() !== '') {
        this.tasks.push({
          text: this.newTask,
          completed: false
        })
        this.newTask = ''
      }
    },
    removeTask(index) {
      this.tasks.splice(index, 1)
    }
  }
}
</script>

<style>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Arial', sans-serif;
  background-color: #f5f5f5;
  color: #333;
}

#app {
  max-width: 600px;
  margin: 0 auto;
  padding: 20px;
}

.container {
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  padding: 20px;
}

h1 {
  text-align: center;
  margin-bottom: 20px;
  color: #2c3e50;
}

.add-task {
  display: flex;
  margin-bottom: 20px;
}

.task-input {
  flex: 1;
  padding: 10px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 16px;
}

.add-btn {
  background-color: #3498db;
  color: white;
  border: none;
  border-radius: 4px;
  padding: 10px 15px;
  margin-left: 10px;
  cursor: pointer;
  transition: background-color 0.3s;
}

.add-btn:hover {
  background-color: #2980b9;
}

.task-list {
  margin-bottom: 20px;
}

.task-item {
  display: flex;
  align-items: center;
  padding: 10px;
  border-bottom: 1px solid #eee;
  transition: background-color 0.3s;
}

.task-item:hover {
  background-color: #f9f9f9;
}

.task-checkbox {
  margin-right: 10px;
}

.task-text {
  flex: 1;
}

.task-item.completed .task-text {
  text-decoration: line-through;
  color: #95a5a6;
}

.delete-btn {
  background-color: #e74c3c;
  color: white;
  border: none;
  border-radius: 4px;
  padding: 5px 10px;
  cursor: pointer;
  transition: background-color 0.3s;
}

.delete-btn:hover {
  background-color: #c0392b;
}

.task-stats {
  text-align: center;
  color: #7f8c8d;
  font-size: 14px;
}
</style>